//
//  QYLuckyLotteryViewController.m
//  QYBaseProject
//
//  Created by Dxc_iOS on 2018/10/12.
//  Copyright © 2018 代星创. All rights reserved.
//

#import "QYLuckyLotteryViewController.h"
#import "UIColor+QYColor.h"
@interface QYLuckyLotteryViewController ()
<UIScrollViewDelegate,UITableViewDelegate,UITableViewDataSource>
{
    UIImageView *navBarHairlineImageView;
    NSArray * scrollContentDic;
    NSInteger endSelectPictureCount;
    UITapGestureRecognizer * gesture;
}
@property (nonatomic, strong) UIScrollView * scrollV;
@property (nonatomic, strong) UITableView * LuckyTableView;
@property (nonatomic, strong) UIImageView * bgImageView;
@property (nonatomic, strong) UIImageView * circleView;
@property (nonatomic, strong) UIImageView * buttonImageV;
@property (nonatomic, strong) UILabel * credientsLabel;
@property (nonatomic, strong) UILabel * countLabel;
@property (nonatomic, strong) UIScrollView * bottomScrollView;
@property (strong, nonatomic) NSTimer * myTimer;

@end

@implementation QYLuckyLotteryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.title = @"抽奖";
    
    _scrollV = [[UIScrollView alloc]init];
    _scrollV.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
    _scrollV.scrollEnabled = YES;
    _scrollV.showsVerticalScrollIndicator = NO;
    
    [self.view addSubview:_scrollV];
    _scrollV.contentSize = CGSizeMake(0,SCREEN_HEIGHT+100);

     [_scrollV addSubview:self.bgImageView];
    
     [self.bgImageView addSubview:_credientsLabel];
     [self.bgImageView addSubview:self.circleView];
     [self.bgImageView addSubview:self.buttonImageV];
    

}

#pragma mark -- 点击事件
-(void)addGestureWithImage{
     CJKTLog(@"点击了抽奖按钮");
    
    
    
    
//    转盘动画 (转盘均匀分成10份)
    
    NSInteger num = 1;//1-10 转盘第几个顺序 （顺时针旋转 谢谢参与为第1格） （服务器返回的）
    NSInteger resultNum = ((11 - num % 10) * 36); //转盘旋转次数
      CJKTLog(@"点击了抽奖按钮 num= %ld \n resultNum=  %ld",num,resultNum);

    CALayer* layer = self.circleView.layer;
    self.circleView.transform = CGAffineTransformMakeRotation(M_PI * resultNum/ 180);
    CABasicAnimation *spin = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
    [spin setFromValue:[NSNumber numberWithFloat:M_PI * 0.0]];
    [spin setToValue:[NSNumber numberWithFloat:resultNum]];
    // spin.byValue = @(5*(M_PI*2));
    [spin setDuration:2.0f];
    [spin setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
    //            spin.fillMode=kCAFillModeForwards;
    //            spin.removedOnCompletion = NO;
    [layer addAnimation:spin forKey:@"geiLuckyAnimation"];
    
   
}
#pragma mark -- 懒加载UI控件
//-(UIScrollView *)scrollV{
//    if (!_scrollV) {
//        _scrollV = [[UIScrollView alloc]init];
//        _scrollV.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
//        _scrollV.scrollEnabled = YES;
//        _scrollV.showsVerticalScrollIndicator = NO;
//        [_scrollV addSubview:self.bgImageView];
//
//    }
//    return _scrollV;
//}
-(UIImageView *)bgImageView{
    if (!_bgImageView) {
        _bgImageView = [[UIImageView alloc]init];
       
        _bgImageView.image = [UIImage imageNamed:@"owner_luckyBgImage"];
        _bgImageView.frame =CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH * 2.03);
        _bgImageView.contentMode = UIViewContentModeScaleAspectFill;
//        _scrollV.contentSize = CGSizeMake(0, SCREEN_HEIGHT+150);
        _bgImageView.userInteractionEnabled = YES;
       
    }
    return _bgImageView;
}
-(UILabel *)credientsLabel{
    if (!_credientsLabel) {
        _credientsLabel = [[UILabel alloc]init];
        _credientsLabel.font = [UIFont fontWithName:@"MicrosoftYaHei" size:14];
        _credientsLabel.textColor = [UIColor qy_colorWithHexString:@"#fed530"];
        _credientsLabel.frame = CGRectMake(280, 86.5, 57, 14);
       
    }
    
    return _credientsLabel;
}
-(UIImageView *)circleView{
    if (!_circleView) {
        _circleView = [[UIImageView alloc]init];
        _circleView.image = [UIImage imageNamed:@"lucky_smallBgImage"];
        
        _circleView.center = CGPointMake(SCREEN_WIDTH/2, SCREEN_HEIGHT/2 - 60 );
       
        //        _circleView.top = 120.0f + NavigationHeight;
        CGFloat circleWidth = SCREEN_WIDTH-2*24.5;
        _circleView.bounds = CGRectMake(0, 0, circleWidth, circleWidth);
        _circleView.contentMode = UIViewContentModeScaleAspectFill;
        
    }
    
    return _circleView;
}
-(UILabel *)countLabel{
    if (!_countLabel) {
        _countLabel = [[UILabel alloc]init];
        _countLabel.font = [UIFont fontWithName:@"MicrosoftYaHei-Bold" size:16];
        _countLabel.textColor = [UIColor qy_colorWithHexString:@"#fed530"];
        _countLabel.frame = CGRectMake(82, CGRectGetMaxY(self.circleView.frame)+25, 10, 16);
        [self.bgImageView addSubview:_countLabel];
    }
    return _countLabel;
}
-(UIImageView *)buttonImageV{
    if (!_buttonImageV) {
        _buttonImageV = [[UIImageView alloc]init];
        _buttonImageV.image = [UIImage imageNamed:@"lucky_buttonImage"];
        _buttonImageV.center = self.circleView.center;
        _buttonImageV.userInteractionEnabled = YES;
        _buttonImageV.bounds = CGRectMake(0, 0, 76, 76);
        _buttonImageV.contentMode = UIViewContentModeScaleAspectFill;
        gesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(addGestureWithImage)];
        [_buttonImageV addGestureRecognizer:gesture];
    }
    
    return _buttonImageV;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
